package com.agentfactory.teleoreactive.interpreter;

import java.util.LinkedList;
import java.util.List;

import com.agentfactory.logic.update.lang.Function;
import com.agentfactory.logic.update.lang.ITerm;
import com.agentfactory.logic.update.lang.Predicate;
import com.agentfactory.logic.update.util.DefaultLogicFactory;
import com.agentfactory.logic.update.util.DefaultLogicPresenter;
import com.agentfactory.logic.update.util.ILogicFactory;
import com.agentfactory.logic.update.util.ILogicPresenter;
import com.agentfactory.platform.core.AgentID;

public class Utilities {
    
    public static final ILogicFactory factory = new DefaultLogicFactory();
    public static final ILogicPresenter presenter = new DefaultLogicPresenter();
	
    public static String createSignature(Predicate id) {
		return id.functor() + ":" + id.size();
	}
    
    public static AgentID toAgentID(ITerm term) {
    	if (!Function.class.isInstance(term)) return null;
    	
    	Function fos = (Function) term;
    	String id = presenter.toString(fos.termAt(0));
    	List<String> addresses = new LinkedList<String>();
    	Function funct = (Function) fos.termAt(1);
    	for (ITerm t: funct) {
    		addresses.add(presenter.toString(t));
    	}
    	
    	return new AgentID(id, addresses, new LinkedList<String>());
    }

}
